package com.mall.mapper;

import com.github.pagehelper.Page;
import com.mall.domain.dto.OrderPageQueryDTO;
import com.mall.domain.po.Order;
import com.mall.domain.vo.OrderVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description: 订单持久层接口
 * @author 勾新杰
 * @version 1.0
 * @date 2024/11/25 10:46
 */
@Mapper
public interface OrderMapper {

    /**
     * 新增订单
     * @param order 订单
     */
    @Insert("insert into `order` (user_id, address_id, total_amount, order_status, create_time, update_time, order_no, payment_time, delivery_time) " +
            "values (#{userId}, #{addressId}, #{totalAmount}, #{orderStatus}, #{createTime}, #{updateTime}, #{orderNo}, #{paymentTime}, #{deliveryTime});")
    void insert(Order order);

    /**
     * 根据订单号查询订单
     * @param orderNo 订单号
     * @return 订单
     */
    @Select("select id, user_id, address_id, total_amount, order_status, create_time, update_time, order_no, payment_time, delivery_time from `order`where order_no = #{orderNo};")
    Order getByOrderNo(Long orderNo);

    /**
     * 根据id查询订单
     * @param id id
     * @return 订单
     */
    @Select("select id, user_id, address_id, total_amount, order_status, create_time, update_time, order_no, payment_time, delivery_time from `order` where id = #{id};")
    Order getById(Long id);

    /**
     * 更新订单
     * @param order 订单
     */
    void update(Order order);

    /**
     * 分页查询订单
     * @param orderPageQueryDTO 分页查询参数
     * @return 订单列表
     */
    Page<OrderVO> page(OrderPageQueryDTO orderPageQueryDTO);

    /**
     * 批量发货
     * @param ids 订单id集合
     */
    void deliverBatch(List<Long> ids, Integer status);

    /**
     * 删除订单
     * @param id 订单id
     */
    @Delete("delete from `order` where id = #{id};")
    void deleteById(Long id);
}
